<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../../css/reset.css" />
    <link rel="stylesheet" type="text/css" href="../../css/register.css" />
</head>

<body>
    <div class="pos">
        <div class="login">
            <span class="close iconfont icon-close"></span>
            <img src="../../img/login/loginlogo.png" alt="">
            <ul>
                <li></li>
                <li class="phone">注册</li>
                <li></li>
            </ul>
            <!-- <form action="" id="form"> -->
            <input style="margin-top: 0;" type="text" name="username" id="username" placeholder="请输入您的账号">

            <input type="password" name="password" id="password" placeholder="请输入密码">

            <input type="password" name="password2" id="password2" placeholder="请再次输入密码">
            <span class="tips"> </span>
            <div class="clear"></div>
            <button class="loginbtn">注册</button>
            <!-- </form> -->

            <p>
                <input type="checkbox" class="xuanze" />
                <span><a href="javascript:;">我同意 《用户使用协议》</a></span>
                <span>
                    已有账号
                    <a href="javascript:;">去登陆</a>
                </span>
            </p>
        </div>
    </div>
    <!-- <script src="../../utils/utils.js"></script> -->
</body>

</html>
<script src="../../utils/jquery.min.js"></script>
<script src="../../utils/ajax.js"></script>
<script>

    $(".loginbtn").on("click",async function () {
        $(".tips").text("")


        let username = $("#username").val()
        let password = $("#password").val()
        let password2 = $("#password2").val()

        if(!username||!password || !password2){
            $(".tips").text("请输入账号或密码")
            return
        }

        if(password!=password2){
            $(".tips").text("两次输入的密码不一致")
            return
        }
        if(!$(".xuanze").prop("checked")){
            $(".tips").text("请阅读协议，并勾选")
            return
        }
 

        // 发送ajax请求
        let [err,results]=await ajax({
            url:api_url+"/register",
            type:"post",
            data:{
                username,
                password,
                password2
            }
        })
        if(err){
            $(".tips").text("出错了")
            return
        }

        if(results.status!=200){
            $(".tips").text( results.msg)
            return
        }
        // console.log(err,results);

        // 注册成功：
        alert("注册成功")
        location.href="./login.html"


    })









</script>